package com.example.crm.dao.Impl;

import com.example.crm.dao.IAdminDAO;
import com.example.crm.pojo.Admin;
import com.example.crm.utils.C3P0Utils;
import lombok.Data;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.springframework.stereotype.Component;

import java.sql.SQLException;

@Component(value = "adminDAO")
public class AdminDAOImpl implements IAdminDAO {

    @Override
    public Admin find(String username, String password) throws SQLException {
        String sql = "select * from admin where username=? and password=?;";
        QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
        Admin admin = runner.query(sql,new BeanHandler<>(Admin.class),username,password);
        return admin;
    }
}
